@extends('admin.layout.layout', ['row' => @$page])
@section('style')
    <style>
        .table .tth{
            background-color: rgba(0, 0, 0, 0.05);
            width: 150px;
            font-weight: bold;
        }
        .table .ttd{
            width: 350px;
        }
        .table .ttt{
            padding: 0;
        }
        .ttt .table{
            margin: 0;
        }
        .ttt .table img + p{
            text-align: center;
            margin: 10px 0 0;
        }
        .tst{
            color: #1e89e0;
            font-weight: 700;
            text-align: center;
            font-size: 1.25rem;
        }
    </style>
@endsection
@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                {{--<div class="item">
                    <a href="/{{ request()->path() }}/create" class="btn btn-sm btn-primary">{{ ts('addnew') }}</a>
                </div>--}}
            </div>
        </div>

        <div>
            <table class="table s3">
                <tbody>
                <tr>
                    <td class="tth">{{ ts('zh') }}</td>
                    <td class="ttd">{{ @$data->unique_id }}</td>
                    <td colspan="4"></td>
                    {{--<td class="tth">{{ ts('bjxtid') }}</td>
                    <td class="ttd">{{ $data->union_id }}</td>--}}
                    {{--<td class="tth">{{ ts('userid') }}</td>
                    <td class="ttd">
                        <input type="text" value="{{ @$data->ubid }}" name="user_id" class="form-control" readonly style="width: 150px;display: inline-block;padding-top: 2px;">
                        --}}{{--@if($data->status==0)
                            <button class="btn btn-primary" onclick="xgUnionId('{{ @$data->ubid }}', '{{ @$data->user_type }}')">{{ ts('xg') }}</button>
                            @if(@$data->ubid)
                                <button class="btn btn-danger ml-3" onclick="delUnionId('{{ $data->id }}')">{{ ts('delete') }}</button>
                            @else
                            @endif
                        @endif--}}{{--
                        --}}{{--<div class="alert alert-danger">{{ ts('dqzt') }}：{{ fdu1($admin) }}</div>--}}{{--
                    </td>--}}

                    {{--<td class="tth">{{ ts('USERTYPE') }}</td>
                    <td class="ttd">{{ ts('USERTYPE'.@$data->user_type) }}</td>--}}
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('baseinformation') }}</td>
                </tr>
                <tr>
                    @if(@$data->user_type == 3)
                        {{--JXSMC--}}
                        <td class="tth">{{ ts('dmmc') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ @$obj->abbr }}</p>
                            <p>{{ @$admin->abbr }}</p>
                        </td>
                        <td class="tth">{{ ts('JXSJB') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ ts('MDTYPE'.@$obj->mdtype) }}</p>
                            <p>{{ ts('mdtype'.@$admin->mdtype) }}</p>
                        </td>
                        <td class="tth">{{ ts('SUPERIORDISTRIBUTOR') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ getJc(@$obj->creator_id) }}</p>
                            <p>{{ getJc(@$admin->creator_id) }}</p>
                        </td>
                    @else
                        {{--JXSMC--}}
                        <td class="tth">{{ ts('companyname') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ @$obj->company_name }}</p>
                            <p>{{ @$admin->company_name }}</p>
                        </td>
                        <td class="tth">{{ ts('GSJC') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ @$obj->abbr }}</p>
                            <p>{{ @$admin->abbr }}</p>
                        </td>
                        <td class="tth"></td>
                        <td></td>

                        {{--<td class="tth">{{ ts('SUPERIORDISTRIBUTOR') }}</td>
                        <td class="ttd">
                            <p class="text-danger">{{ getJc(@$obj->creator_id) }}</p>
                            <p>{{ getJc(@$admin->creator_id) }}</p>
                        </td>--}}
                    @endif

                </tr>
                <tr>
                    <td class="tth">{{ ts('phonenumber') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ @$obj->extension }} {{ @$obj->phone_number }}</p>
                        <p>{{ @$admin->extension }} {{ @$admin->phone_number }}</p>
                    </td>
                    <td class="tth">{{ ts('email') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ @$obj->email_address }}</p>
                        <p>{{ @$admin->email_address }}</p>
                    </td>
                    <td class="tth">{{ ts('status') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ ts('ust'.@$obj->status) }}</p>
                        <p>
                            @empty($admin->deleted_at)
                                {{ ts('ust'.@$admin->status) }}
                            @else
                                {{ ts('JY') }}
                            @endif
                        </p>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('regionInformation') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('region') }}</td>
                    <td>
                        <p class="text-danger">{{ ts('region_master.'.@$obj->region_id) }}</p>
                        <p>{{ ts('region_master.'.@$admin->region_id) }}</p>
                    </td>
                    <td class="tth">{{ ts('province') }}</td>
                    <td>
                        <p class="text-danger">{{ ts('province_master.'.@$obj->province_id) }}</p>
                        <p>{{ ts('province_master.'.@$admin->province_id) }}</p>
                    </td>
                    <td class="tth">{{ ts('city') }}</td>
                    <td>
                        <p class="text-danger">{{ ts('cities.'.@$obj->city) }}</p>
                        <p>{{ ts('cities.'.@$admin->city) }}</p>
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('addresss') }}</td>
                    <td class="ttd" colspan="5">
                        <p class="text-danger">{{ @$obj->address }}</p>
                        <p>{{ @$admin->address }}</p>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('contactinformation') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('XINGMING') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ @$obj->first_name }}</p>
                        <p>{{ @$admin->first_name }}</p>
                    </td>
                    <td class="tth">{{ ts('CEllPHONE') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ @$obj->cell_phone }}</p>
                        <p>{{ @$admin->cell_phone }}</p>
                    </td>
                    <td class="tth">{{ ts('WECHATID') }}</td>
                    <td class="ttd">
                        <p class="text-danger">{{ @$obj->wechat_id }}</p>
                        <p>{{ @$admin->wechat_id }}</p>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('BEIZHU') }}</td>
                </tr>
                <tr>
                    <td colspan="6" height="64">
                        <p class="text-danger">{{ @$obj->note }}</p>
                        <p>{{ @$admin->note }}</p>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="my-4">
                @if($data->status==0)
                    <button type="button" href="/{{ request()->path() }}/edit" class="btn btn-primary" onclick="tbJXS(1)">{{ ts('confirm') }}</button>
                    <button type="button" href="/{{ request()->path() }}/edit" class="btn btn-danger ml-3" onclick="tbJXS(3)">{{ ts('PQ') }}</button>
                @elseif($data->status==5)
                    <button type="button" href="/{{ request()->path() }}/edit" class="btn btn-primary" onclick="tbJXS(2)">{{ ts('addnew') }}</button>
                    <button type="button" href="/{{ request()->path() }}/edit" class="btn btn-danger ml-3" onclick="tbJXS(3)">{{ ts('PQ') }}</button>
                @else
                    <div class="alert alert-info">
                        <div>{{ ts('dqzt') }}：<strong>{{ ts('TBS'.@$data->status) }}</strong></div>
                        <div>{{ ts('gxrq') }}：<strong>{{ fdate2(@$data->updated_at) }}</strong></div>
                    </div>
                @endif
            </div>
        </div>

        <div class="modal fade" id="UnionModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5></h5>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-item">
                                <div class="form-label">{{ ts('GLYH') }}</div>
                                <div class="form-input">
                                    <select name="user_id" id="" class="form-control">
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                            <div class="text-center">
                                <button class="btn btn-primary" type="button" onclick="handleXgId('{{ $data->id }}')">{{ ts('confirm') }}</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>


@endsection



@section('script')
    <script>
        function handleXgId(id) {
            var user_id = $('#UnionModal select[name="user_id"]').val();
            if (!user_id) {
                alert('请选择关联用户！');
            }

            var form = {
                t: 'changeUserId',
                id: id,
                user_id: user_id
            };
            var r = confirm('确定修改关联用户？修改后该ID将会关联系统内此用户')
            if (r == true) {
                request.post('/admin/ajax/user_sync', form)
                    .then(function (d) {
                        console.log(d);
                        alert(d.msg || '修改成功');
                        window.location.reload();
                    })
                    .catch(function (d) {
                        console.log(d);
                        alert(d.msg || '修改失败');
                        window.location.reload();
                    })
            }
        }

        function delUnionId(id) {
            var form = {
                t: 'delUnionId',
                id: id,
            };
            var r = confirm('确定删除关联？删除后不再关联此用户');
            if (r == true) {
                request.post('/admin/ajax/user_sync', form)
                    .then(function (d) {
                        console.log(d);
                        alert(d.msg || '删除成功');
                        window.location.reload();
                    })
                    .catch(function (d) {
                        console.log(d);
                        alert(d.msg || '删除失败');
                        window.location.reload();
                    })
            }
        }
        function xgUnionId(id, user_type) {
            var form = {
                t: 'getUid1',
                user_id: id,
                user_type: user_type,
            };
            request.post('/admin/ajax/user_sync', form)
                .then(function (d) {
                    var data= d.data;
                    if (data.length < 1) {
                        alert('系统内没有尚未关联的用户！')
                    } else {
                        $('#UnionModal select[name="user_id"]').empty().append(makeSelectOptionsOnly(d.data, id));
                        $('#UnionModal').modal();
                    }
                })
        }

        function tbJXS(type) {
            var msg;
            if (type == 1)  {
                msg = '确定同步用户信息？确认后将在目前系统中新增数据'
            } else if(type == 2) {
                msg = '确定新增用户信息？确认后将更新目前系统中数据'
            } else if(type == 3) {
                msg = '确定抛弃该信息？不影响目前系统中的数据'
            }
            mySwal(msg)
                .then(function (d) {
                    var form = {
                        t: 'update',
                        id: '{{ $data->id }}',
                        type: type,
                    };
                    request.post('/admin/ajax/user_sync', form)
                        .then(function (d) {
                            sweetAlert('', 'SUCCESS', 'success').then(function (d) {
                                window.location.reload();
                            })
                        })
                        .catch(function (d) {
                            console.log('error2', d)
                            sweetAlert('', d.msg || 'error', 'error')
                        })
                })

        }
    </script>
@endsection